package app.gui;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;

import javax.swing.JPanel;

import app.board.Board;

// ------------------------------------------------
class MyCanvas extends JPanel implements MouseListener, MouseMotionListener {
	private ApplicationFrame _parent;
    private Board _board;
    
	// ------------------------
	public MyCanvas(ApplicationFrame parent) {
		super();
		this._parent = parent;
		setPreferredSize(new Dimension(400, 500));
		setBackground(Color.WHITE);

		addMouseListener(this);
		addMouseMotionListener(this);
		
		_board = new Board(8, 16);
	}

	// ------------------------
	public void paint(Graphics g) {
		super.paint(g);
		_board.drawBoard(g);
	}

	@Override
	public void mouseDragged(MouseEvent e) {
		// TODO Auto-generated method stub

	}

	@Override
	public void mouseMoved(MouseEvent e) {

		int _x = e.getX();
		int _y = e.getY();

		Point p=_board.getClosestPoint(_x, _y);
		
		if (p!=null)
		System.out.println("x=" + p.getX() + ", y=" + p.getY());
//		int _x = e.getX();
//		int _y = e.getY();
//
//		_board.getClosestPoint(_x, _y);
//		Point p=_board.getClosestPoint(_x, _y);
//		System.out.println("x=" + p.getX() + ", y=" + p.getY());
//		 points.add(new Point(x, y));
//		 repaint();
	}

	@Override
	public void mouseClicked(MouseEvent e) {
//
//		int _x = e.getX();
//		int _y = e.getY();
//
//		_board.getClosestPoint(_x, _y);
	}

	@Override
	public void mousePressed(MouseEvent e) {

	}

	@Override
	public void mouseReleased(MouseEvent e) {

	}

	@Override
	public void mouseEntered(MouseEvent e) {
		// TODO Auto-generated method stub

	}

	@Override
	public void mouseExited(MouseEvent e) {
		// TODO Auto-generated method stub

	}
}
